﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using AutoR.Models;
using AutoR.Services;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services;

namespace AutoR.ViewModels.Setting
{
	// Token: 0x0200008D RID: 141
	public class AddShipViewModel : BindableBase, INavigationAware, INavigatedAware, INavigatingAware
	{
		// Token: 0x17000098 RID: 152
		// (get) Token: 0x0600027B RID: 635 RVA: 0x000466A5 File Offset: 0x000448A5
		// (set) Token: 0x0600027C RID: 636 RVA: 0x000466B0 File Offset: 0x000448B0
		private UserFleet sourceFleet
		{
			[CompilerGenerated]
			get
			{
				return this.<sourceFleet>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<sourceFleet>k__BackingField, value))
				{
					return;
				}
				this.<sourceFleet>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.sourceFleet);
			}
		}

		// Token: 0x17000099 RID: 153
		// (get) Token: 0x0600027D RID: 637 RVA: 0x000466E0 File Offset: 0x000448E0
		private INavigationService NavigationService { get; }

		// Token: 0x1700009A RID: 154
		// (get) Token: 0x0600027E RID: 638 RVA: 0x000466E8 File Offset: 0x000448E8
		private IPageDialogService PageDialogService { get; }

		// Token: 0x1700009B RID: 155
		// (get) Token: 0x0600027F RID: 639 RVA: 0x000408F6 File Offset: 0x0003EAF6
		public GameData Game
		{
			get
			{
				return Runtime.Game;
			}
		}

		// Token: 0x1700009C RID: 156
		// (get) Token: 0x06000280 RID: 640 RVA: 0x000466F0 File Offset: 0x000448F0
		// (set) Token: 0x06000281 RID: 641 RVA: 0x000466F8 File Offset: 0x000448F8
		public ObservableCollection<UserShip> List
		{
			[CompilerGenerated]
			get
			{
				return this.<List>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<List>k__BackingField, value))
				{
					return;
				}
				this.<List>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.List);
			}
		}

		// Token: 0x1700009D RID: 157
		// (get) Token: 0x06000282 RID: 642 RVA: 0x00046728 File Offset: 0x00044928
		// (set) Token: 0x06000283 RID: 643 RVA: 0x00046730 File Offset: 0x00044930
		public UserShip SelectShip
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectShip>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<SelectShip>k__BackingField, value))
				{
					return;
				}
				this.<SelectShip>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectShip);
			}
		}

		// Token: 0x1700009E RID: 158
		// (get) Token: 0x06000284 RID: 644 RVA: 0x00046760 File Offset: 0x00044960
		// (set) Token: 0x06000285 RID: 645 RVA: 0x00046768 File Offset: 0x00044968
		public int ShipType
		{
			[CompilerGenerated]
			get
			{
				return this.<ShipType>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<ShipType>k__BackingField == value)
				{
					return;
				}
				this.<ShipType>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.ShipType);
			}
		}

		// Token: 0x1700009F RID: 159
		// (get) Token: 0x06000286 RID: 646 RVA: 0x00046795 File Offset: 0x00044995
		public DelegateCommand OKCommand { get; }

		// Token: 0x06000287 RID: 647 RVA: 0x0004679D File Offset: 0x0004499D
		public AddShipViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
		{
			this.NavigationService = navigationService;
			this.PageDialogService = pageDialogService;
			this.GenList();
			this.OKCommand = new DelegateCommand(new Action(this.OnOKCommandExecuted));
		}

		// Token: 0x06000288 RID: 648 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatedFrom(INavigationParameters parameters)
		{
		}

		// Token: 0x06000289 RID: 649 RVA: 0x000467D0 File Offset: 0x000449D0
		public void OnNavigatedTo(INavigationParameters parameters)
		{
			if (parameters.ContainsKey("fleet"))
			{
				this.sourceFleet = (UserFleet)parameters["fleet"];
			}
		}

		// Token: 0x0600028A RID: 650 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatingTo(INavigationParameters parameters)
		{
		}

		// Token: 0x0600028B RID: 651 RVA: 0x000467F8 File Offset: 0x000449F8
		public void GenList()
		{
			List<UserShip> list = this.Game.UserShip.ToList<UserShip>();
			if (this.ShipType != 0)
			{
				int[] id = new int[]
				{
					0,
					1,
					2,
					3,
					4,
					5,
					6,
					7,
					8,
					9,
					10,
					11,
					12,
					13,
					14,
					15,
					16,
					23,
					24
				};
				list = (from i in list
				where i.Type == (ShipType)id[this.ShipType]
				select i).ToList<UserShip>();
			}
			list = (from i in list
			orderby i.level descending, i.Type descending
			select i).ToList<UserShip>();
			this.List = new ObservableCollection<UserShip>(list);
		}

		// Token: 0x0600028C RID: 652 RVA: 0x000468B8 File Offset: 0x00044AB8
		private async void OnOKCommandExecuted()
		{
			if (this.sourceFleet != null)
			{
				this.Game.DelayTask.ChangeBoatQueue.Enqueue(string.Format("{0}|{1}|{2}|0", this.sourceFleet.id, this.SelectShip.id, this.sourceFleet.ships.Count));
				await this.PageDialogService.DisplayAlertAsync("提示", "已将换船请求加入队列", "确定");
			}
			await this.NavigationService.GoBackAsync();
		}
	}
}
